package com.xingdata.jjxc.utils;

import java.util.HashMap;

import android.graphics.Bitmap;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.util.LruCache;

public class BitmapThread extends Thread {
	private final String TAG = "BitmapThread";
	private Object synchronizedObject = new Object();
	private String url;
	private LruCache<String, Bitmap> bitMap;
	private Handler handler;
	private Float fMulriple;

	public BitmapThread(String url, Handler handler,LruCache<String, Bitmap> cache,Float fMulriple) {
		this.url = url;
		this.handler = handler;
		this.bitMap = cache;
		this.fMulriple=fMulriple;
	}

	@Override
	public void run() {
		super.run();
		synchronized (synchronizedObject) {
			Log.i(TAG, "正在获取缩略图" + url);
			String imageURL = url.replaceAll(".mp4", ".jpg");
			Bitmap bitmap = SDCardTools.getSDImage(imageURL,fMulriple);
			if (bitmap == null) {
				if (url.startsWith("http")) {
					bitmap = VideoTools.createNetVideoThumbnail(url);
				}else {
					bitmap = VideoTools.createVideoThumbnail(url);
				}
			
//				SDCardTools.SaveUrlImage(imageURL, bitmap);
			}
			BitmapCache.put(ImageTools.changeImageName(imageURL), bitmap);
			Message message = new Message();
			message.what = MessageCode.MessageCode_RefreshControl;
			handler.sendMessage(message);
		}
		super.run();

	}
}
